package com.taobao.server;

import java.lang.reflect.Field;
import java.util.List;

import com.taobao.factory.TBFactory;

public abstract class CommonServer {

    public CommonServer() {
        List<Object> objectList = TBFactory.initAttributeObject(this.getClass());
        Field[] fields = this.getClass().getDeclaredFields();
        int no = 0;
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            field.setAccessible(true);
            String fieldName = field.getName();
            int flag = fieldName.indexOf("Dao");
            if (flag != -1 && (flag + "Dao".length() == fieldName.length() || flag + "DaoSingle".length() == fieldName.length())) {
                try {
                    field.set(this, objectList.get(no));
                    no++;
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
